import 'package:get/get.dart';
import 'package:study_demo/base/BaseController.dart';

class DragGridViewController extends BaseController {
  final items = List.generate(20, (index) => 'Item ${index + 1}').obs;
  final draggedIndex = (-1).obs; // 使用-1表示没有拖动
  final isPressed = false.obs;
  final pressedIndex = (-1).obs; // 使用-1表示没有按下

  void swapItems(int fromIndex, int toIndex) {
    final temp = items[fromIndex];
    items[fromIndex] = items[toIndex];
    items[toIndex] = temp;
  }

  void setPressed(int index, bool pressed) {
    isPressed.value = pressed;
    pressedIndex.value = pressed ? index : -1; // 按下时设置索引，否则设为-1
  }

  void startDrag(int index) {
    draggedIndex.value = index;
    isPressed.value = false;
    pressedIndex.value = -1; // 开始拖动时重置按下状态
  }

  void endDrag() {
    draggedIndex.value = -1; // 拖动结束重置为-1
  }
}
